package cn.bocweb.spinning.view.dialog;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import cn.bocweb.spinning.R;

/**
 * Created by chenchangxing on 15/12/21.
 */
public class SetQuesWarehouseDialog extends AlertDialog {

    OnDialogClickListener onDialogClickListener;

    String id;
    String content;
    String count;
    Context context;
    TextView dialogContent;
    Button btnSubmit;
    public interface OnDialogClickListener{
        public void click(String id, String content, String count);
    }

    public void setOnDialogClickListener(OnDialogClickListener onDialogClickListener) {
        this.onDialogClickListener = onDialogClickListener;
    }

    public SetQuesWarehouseDialog(Context context) {
        super(context);
        this.context = context;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public String getContent() {
        return content;
    }

    public String getCount() {
        return count;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setCount(String count) {
        this.count = count;
    }

    public SetQuesWarehouseDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_set_ques_warehouse);
        dialogContent = (TextView)findViewById(R.id.dialog_content);
        btnSubmit = (Button)findViewById(R.id.btn_submit);

        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onDialogClickListener.click(id, content, count);
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        SpannableString spannableString = new SpannableString("您选择的是" + content + ",一共" + count + "题");
        spannableString.setSpan(new TextAppearanceSpan(context, R.style.text_red), (5 + content.length() + 3), (5 + content.length() + 3 + count.length()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        dialogContent.setText(spannableString);
    }
}
